package org.metasketch.editor.timeline;

import java.util.ArrayList;
import java.util.List;

import org.metasketch.editor.Editor;

public class SnapshotManager {

	static Editor editor;
	static SnapshotEngine snapshotEngine = new SnapshotEngine();

	static List<SnapshotListener> listeners = new ArrayList<SnapshotListener>();

	static String currentPerspectiveName;
	static String currentDiagramId;
	static String currentToolId;

	public static void takeSnapshot() {
		snapshotEngine.takeSnapshot(editor.getProject());
		triggerListeners();
	}

	public static void clearAll() {
		snapshotEngine.clear();
		triggerListeners();
	}

	public static void undo() {
		snapshotEngine.undo(editor);
		triggerListeners();
	}

	public static void redo() {
		snapshotEngine.redo(editor);
		triggerListeners();
	}

	public static Editor getEditor() {
		return editor;
	}

	public static void setEditor(Editor editor) {
		SnapshotManager.editor = editor;
	}

	public static boolean canUndo() {
		return snapshotEngine.canUndo();
	}

	public static boolean canRedo() {
		return snapshotEngine.canRedo();
	}

	public static void addListener(SnapshotListener listener) {
		listeners.add(listener);
	}

	public static void removeListener(SnapshotListener listener) {
		listeners.remove(listener);
	}

	protected static void triggerListeners() {
		for (SnapshotListener listener : listeners) {
			listener.changedHistory();
		}
	}

	public static String getCurrentPerspectiveName() {
		return currentPerspectiveName;
	}

	public static void setCurrentPerspectiveName(String currentPerspectiveName) {
		SnapshotManager.currentPerspectiveName = currentPerspectiveName;
	}

	public static String getCurrentDiagramId() {
		return currentDiagramId;
	}

	public static void setCurrentDiagramId(String aCurrentDiagramId) {
		SnapshotManager.currentDiagramId = aCurrentDiagramId;
	}

	public static String getCurrentToolId() {
		return currentToolId;
	}

	public static void setCurrentToolId(String currentToolId) {
		SnapshotManager.currentToolId = currentToolId;
	}

}
